﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTV
{
    public partial class update : Form
    {
        DBHelper db = new DBHelper();
        DataSet set = new DataSet();
        qianduan qd = new qianduan();
        
        string name;
        public string pd;
        public int xb;
        public  string i = "";
        public string e = "";
        public string s = "";
        public string w = "";
        public string tup = "";
        public update()
        {
            InitializeComponent();
        }

        private void update_Load(object sender, EventArgs e)
        {

            

            this.pictureBox1.Image = Image.FromFile("C: \\Users\\cyj\\Desktop\\图片路径1\\" + tup + "");




            db.OpenConnection();
            string sql = "select * from singer_type";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, db.Connection);
            adapter.Fill(set, "singer_type");
            this.comboBox2.DataSource = set.Tables["singer_type"];
            this.comboBox2.ValueMember = "singertype_id";
            this.comboBox2.DisplayMember = "singertype_name";
            
            this.textBox2.Text = i;
            this.comboBox2.Text = s;
            this.textBox1.Text = w;

            if (xb==1)
            {
                this.radioButton1.Checked = true;
            }else if (xb == 2)
            {
                this.radioButton2.Checked = true;
            }
            else if (xb == 3)
            {
                this.radioButton3.Checked = true;
            }

            db.CloseConnection();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            db.OpenConnection();
            chaxun_geshou_xinxi c = new chaxun_geshou_xinxi();

            string sql;
            string leixing;
            if (this.comboBox2.Text == "大陆")
            {
                leixing = "1";
            }
            else if (this.comboBox2.Text == "香港")
            {
                leixing = "2";
            }
            else if (this.comboBox2.Text == "台湾")
            {
                leixing = "3";
            }
            else if (this.comboBox2.Text == "欧美")
            {
                leixing = "4";
            }
            else if (this.comboBox2.Text == "日韩")
            {
                leixing = "5";
            }
            else
            {
                leixing = "0";
                MessageBox.Show("有误");
                return;
            }
            
            if (name==null)
            {
                MessageBox.Show("图片未修改");
                return;
            }



            if (this.radioButton1.Checked = true)
            {
                sql = "update [dbo].[singer_info] set singer_name=N'" + this.textBox2.Text + "',singertype_id='" + leixing + "',singer_gender=N'" + this.radioButton1.Text + "',singer_photo_url=N'" + name + "',singer_description=N'" + this.textBox1.Text + "'where singer_name=N'" + i + "'";
                
            }
            else if (this.radioButton2.Checked = true)
            {
                sql = "update [dbo].[singer_info] set singer_name=N'" + this.textBox2.Text + "',singertype_id='" + leixing + "',singer_gender=N'" + this.radioButton2.Text + "',singer_photo_url=N'" + name + "',singer_description=N'" + this.textBox1.Text + "'where singer_name=N'" + i + "'";
            }
            else if (this.radioButton3.Checked = true) { 

                sql = "update [dbo].[singer_info] set singer_name=N'" + this.textBox2.Text + "',singertype_id='" + leixing + "',singer_gender=N'" + this.radioButton3.Text + "',singer_photo_url=N'" + name + "',singer_description=N'" + this.textBox1.Text + "'where singer_name=N'" + i + "'";
        }
            else
            {
                sql = "";
                return;
            }
            SqlCommand comm = new SqlCommand(sql,db.Connection);
            int panduan = comm.ExecuteNonQuery();
            if (panduan>0)
            {
                MessageBox.Show("修改成功");
                this.Close();

            }
            db.CloseConnection();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //弹出选择文件框
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //打开文件框
            DialogResult result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                // Image.FromFile从路径中拿到图片
                this.pictureBox1.Image = Image.FromFile(openFileDialog.FileName);
                name = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
            }
        }
    }
}
